import { createEmail } from '@/axios/api/outlook/createEmail';
import { ElNotification } from 'element-plus';
import { useCounterStore } from '@/stores/counter';
const counterStore = useCounterStore();

export default function () {


    // 显示通知消息
    function showMessage(type: number, message: string) {
        const title = type === 200 ? 'Success' : 'Error';
        ElNotification({
            title: title,
            message: message,
            type: type === 200 ? 'success' : 'error',
        });
    }



    // 创建邮件

    async function createEmailData(id: number) {
        if(id !=1 && id!=2){
            showMessage(500, '请选择有效的模板');
            return;
        }
        counterStore.excelData_pinia=[];
        counterStore.flag=true;
        try {
            let res:any = await createEmail(id);
            if (res.code === 200) {
                showMessage(200, '创建成功');
                counterStore.excelData_pinia=res.data;
                counterStore.flag=false;

            } else {
                showMessage(500, res.message);
                counterStore.excelData_pinia=res.data;
                counterStore.flag=false;
            }

        }catch (error:any) {
            showMessage(500, error.message);
            counterStore.flag=false;
        }

    }
    return {
        createEmailData
    }
};